package jdbchomework;

import java.sql.*;
import java.util.*;

;
public class TestPrepareStatement {

	public static void main(String[] args) {
		Scanner sca = new Scanner(System.in);
		Connection con = null;
		PreparedStatement ps = null;
		try {
			con = JdbcTools.getConn();
			con.setAutoCommit(false);
			String sql = "insert into bbc values(?,?)";
			ps = con.prepareStatement(sql);
			System.out.println("Start time: " + new java.util.Date());
			for (int i = 1; i < 10000; i++) {
				ps.setInt(1, i);
				ps.setString(2, "-->:" + i + "<--");
				ps.addBatch();
				if (i % 100 == 0) {

					ps.executeBatch();
				}

			}

			System.out.println("Over time:" + new java.util.Date());

			con.commit();
		} catch (Exception e) {
			e.printStackTrace();
			try {
				con.rollback();
			} catch (Exception ee) {
				ee.printStackTrace();
			}
		} finally {
			JdbcUtil.close(null, ps, con);
		}

	}

}
